home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gpp-1_42.lha / g++-1.42.0 / cplus-field.c < prev    next >
C/C++ Source or Header  |  1991-10-19  |  18KB  |  919 lines

  1. /************************************************************************/
  2. /*                                    */
  3. /*        cplus-field.c                        */
  4. /*                                    */
  5. /*    Code for handling XREF output from g++                */
  6. /*                                    */
  7. /************************************************************************/
  8.  
  9.  
  10. #ifdef FIELD_XREF
  11.  
  12. #include "config.h"
  13. #include "tree.h"
  14. #include "cplus-tree.h"
  15. #include "input.h"
  16.  
  17. #include <stdio.h>
  18. #include <ctype.h>
  19. #include <strings.h>
  20.  
  21.  
  22.  
  23.  
  24. /************************************************************************/
  25. /*                                    */
  26. /*    Common definitions                        */
  27. /*                                    */
  28. /************************************************************************/
  29.  
  30. typedef int    Integer;
  31. typedef char *    String;
  32.  
  33.  
  34. #ifndef TRUE
  35. #define TRUE 1
  36. #endif
  37. #ifndef FALSE
  38. #define FALSE 0
  39. #endif
  40. #ifndef NULL
  41. #define NULL 0
  42. #endif
  43.  
  44.  
  45. #define PALLOC(typ) ((typ *) calloc(1,sizeof(typ)))
  46.  
  47.  
  48. #define SALLOC(str) ((String) ((str == NULL) ? NULL : (strcpy(malloc(strlen(str)+1),str))))
  49. #define SFREE(str) (str != NULL && (free(str),0))
  50.  
  51. #define STREQL(s1,s2) (strcmp((s1),(s2)) == 0)
  52. #define STRNEQ(s1,s2) (strcmp((s1),(s2)) != 0)
  53. #define STRLSS(s1,s2) (strcmp((s1),(s2)) < 0)
  54. #define STRLEQ(s1,s2) (strcmp((s1),(s2)) <= 0)
  55. #define STRGTR(s1,s2) (strcmp((s1),(s2)) > 0)
  56. #define STRGEQ(s1,s2) (strcmp((s1),(s2)) >= 0)
  57.  
  58.  
  59.  
  60.  
  61.  
  62. /************************************************************************/
  63. /*                                    */
  64. /*    Type definitions                        */
  65. /*                                    */
  66. /************************************************************************/
  67.  
  68.  
  69. typedef struct _XREF_FILE *    XREF_FILE;
  70. typedef struct _XREF_SCOPE *    XREF_SCOPE;
  71.  
  72.  
  73.  
  74. typedef struct _XREF_FILE {
  75.    String name;
  76.    XREF_FILE next;
  77. } XREF_FILE_INFO;
  78.  
  79.  
  80.  
  81.  
  82.  
  83. typedef struct _XREF_SCOPE {
  84.    Integer gid;
  85.    Integer lid;
  86.    XREF_FILE file;
  87.    Integer start;
  88.    XREF_SCOPE outer;
  89. } XREF_SCOPE_INFO;
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. /************************************************************************/
  97. /*                                    */
  98. /*    Local storage                            */
  99. /*                                    */
  100. /************************************************************************/
  101.  
  102.  
  103. static    char        doing_xref = 0;
  104. static    FILE *        xref_file = NULL;
  105. static    char        xref_name[1024];
  106. static    XREF_FILE    all_files = NULL;
  107. static    String        wd_name = NULL;
  108. static    XREF_SCOPE    cur_scope = NULL;
  109. static    Integer     scope_ctr = 0;
  110. static    XREF_FILE    last_file = NULL;
  111. static    tree        last_fct = NULL;
  112.  
  113.  
  114.  
  115.  
  116. /************************************************************************/
  117. /*                                    */
  118. /*    Forward definitions                        */
  119. /*                                    */
  120. /************************************************************************/
  121.  
  122.  
  123. extern    void        FIELD_xref_begin();
  124. extern    void        FIELD_xref_end();
  125. extern    void        FIELD_xref_file();
  126. extern    void        FIELD_xref_start_scope();
  127. extern    void        FIELD_xref_end_scope();
  128. extern    void        FIELD_xref_ref();
  129. extern    void        FIELD_xref_decl();
  130. extern    void        FIELD_xref_call();
  131. extern    void        FIELD_xref_function();
  132. extern    void        FIELD_xref_assign();
  133. extern    void        FIELD_xref_hier();
  134. extern    void        FIELD_xref_member();
  135.  
  136.  
  137. static    void        gen_assign();
  138. static    XREF_FILE    find_file();
  139. static    String        filename();
  140. static    String        fctname();
  141. static    String        declname();
  142. static    void        simplify_type();
  143. static    String        fixname();
  144. static    void        open_xref_file();
  145.  
  146. extern    char *        type_as_string();
  147.  
  148.  
  149.  
  150.  
  151. /************************************************************************/
  152. /*                                    */
  153. /*    FIELD_xref_begin -- start cross referencing            */
  154. /*                                    */
  155. /************************************************************************/
  156.  
  157.  
  158. void
  159. FIELD_xref_begin(file)
  160.    String file;
  161. {
  162.    String s,t;
  163.  
  164.    doing_xref = 1;
  165.  
  166.    if (file != NULL && STRNEQ(file,"-")) {
  167.       open_xref_file(file);
  168.       FIELD_xref_file(file);
  169.     };
  170. };
  171.  
  172.  
  173.  
  174.  
  175.  
  176. /************************************************************************/
  177. /*                                    */
  178. /*    FIELD_xref_end -- finish cross referencing            */
  179. /*                                    */
  180. /************************************************************************/
  181.  
  182.  
  183. void
  184. FIELD_xref_end(ect)
  185.    int ect;
  186. {
  187.    XREF_FILE xf;
  188.  
  189.    if (!doing_xref) return;
  190.  
  191.    xf = find_file(input_filename);
  192.    if (xf == NULL) return;
  193.  
  194.    while (cur_scope != NULL) {
  195.       FIELD_xref_end_scope(cur_scope->gid,0,0,0,0);
  196.     };
  197.  
  198.    doing_xref = 0;
  199.  
  200.    if (xref_file == NULL) return;
  201.  
  202.    fclose(xref_file);
  203.  
  204.    xref_file = NULL;
  205.    all_files = NULL;
  206.  
  207.    if (ect > 0) unlink(xref_name);
  208. };
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215. /************************************************************************/
  216. /*                                    */
  217. /*    FIELD_xref_file -- handle file xrefing                */
  218. /*                                    */
  219. /************************************************************************/
  220.  
  221.  
  222. void
  223. FIELD_xref_file(name)
  224.    String name;
  225. {
  226.    XREF_FILE xf;
  227.    char wdbuf[1024];
  228.  
  229.    if (!doing_xref || name == NULL) return;
  230.  
  231.    if (xref_file == NULL) {
  232.       open_xref_file(name);
  233.       if (!doing_xref) return;
  234.     };
  235.  
  236.    if (all_files == NULL) {
  237.       fprintf(xref_file,"SCP * 0 0 0 0 RESET\n");
  238.     };
  239.  
  240.    xf = find_file(name);
  241.    if (xf != NULL) return;
  242.  
  243.    xf = PALLOC(XREF_FILE_INFO);
  244.    xf->name = SALLOC(name);
  245.    xf->next = all_files;
  246.    all_files = xf;
  247.  
  248.    if (wd_name == NULL) {
  249.       getwd(wdbuf);
  250.       wd_name = SALLOC(wdbuf);
  251.     };
  252.  
  253.    fprintf(xref_file,"FIL %s %s 0\n",name,wd_name);
  254.  
  255.    filename(xf);
  256.    fctname(NULL);
  257. };
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264. /************************************************************************/
  265. /*                                    */
  266. /*    FIELD_xref_start_scope -- begin a scope             */
  267. /*    FIELD_xref_end_scope -- finish a scope                */
  268. /*                                    */
  269. /************************************************************************/
  270.  
  271.  
  272. void
  273. FIELD_xref_start_scope(id)
  274.    Integer id;
  275. {
  276.    XREF_SCOPE xs;
  277.    XREF_FILE xf;
  278.  
  279.    if (!doing_xref) return;
  280.    xf = find_file(input_filename);
  281.  
  282.    xs = PALLOC(XREF_SCOPE_INFO);
  283.    xs->file = xf;
  284.    xs->start = lineno;
  285.    if (xs->start <= 0) xs->start = 1;
  286.    xs->gid = id;
  287.    xs->lid = ++scope_ctr;
  288.    xs->outer = cur_scope;
  289.    cur_scope = xs;
  290. };
  291.  
  292.  
  293.  
  294.  
  295.  
  296. void
  297. FIELD_xref_end_scope(id,inid,prm,keep,trns)
  298.    Integer id;
  299.    Integer inid;
  300.    Integer prm,keep,trns;
  301. {
  302.    XREF_FILE xf;
  303.    XREF_SCOPE xs,lxs,oxs;
  304.    String stype;
  305.  
  306.    if (!doing_xref) return;
  307.    xf = find_file(input_filename);
  308.    if (xf == NULL) return;
  309.  
  310.    lxs = NULL;
  311.    for (xs = cur_scope; xs != NULL; xs = xs->outer) {
  312.       if (xs->gid == id) break;
  313.       lxs = xs;
  314.     };
  315.    if (xs == NULL) return;
  316.  
  317.    if (inid != 0) {
  318.       for (oxs = cur_scope; oxs != NULL; oxs = oxs->outer) {
  319.      if (oxs->gid == inid) break;
  320.        };
  321.       if (oxs == NULL) return;
  322.       inid = oxs->lid;
  323.     };
  324.  
  325.    if (prm == 2) stype = "SUE";
  326.    else if (prm != 0) stype = "ARGS";
  327.    else if (keep == 2 || inid != 0) stype = "INTERN";
  328.    else stype = "EXTERN";
  329.  
  330.    fprintf(xref_file,"SCP %s %d %d %d %d %s\n",
  331.           filename(xf),xs->start,lineno,xs->lid,inid,stype);
  332.  
  333.    if (lxs == NULL) cur_scope = xs->outer;
  334.    else lxs->outer = xs->outer;
  335.  
  336.    free(xs);
  337. };
  338.  
  339.  
  340.  
  341.  
  342.  
  343. /************************************************************************/
  344. /*                                    */
  345. /*    FIELD_xref_ref -- handle reference                */
  346. /*                                    */
  347. /************************************************************************/
  348.  
  349.  
  350. void
  351. FIELD_xref_ref(fct,name)
  352.    tree fct;
  353.    String name;
  354. {
  355.    XREF_FILE xf;
  356.  
  357.    if (!doing_xref) return;
  358.    xf = find_file(input_filename);
  359.    if (xf == NULL) return;
  360.  
  361.    fprintf(xref_file,"REF %s %d %s %s\n",
  362.           filename(xf),lineno,fctname(fct),name);
  363. };
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370. /************************************************************************/
  371. /*                                    */
  372. /*    FIELD_xref_decl -- handle declaration                */
  373. /*                                    */
  374. /************************************************************************/
  375.  
  376.  
  377. void
  378. FIELD_xref_decl(fct,decl)
  379.    tree fct;
  380.    tree decl;
  381. {
  382.    XREF_FILE xf;
  383.    String cls;
  384.    String name;
  385.    char buf[10240];
  386.  
  387.    if (!doing_xref) return;
  388.    xf = find_file(input_filename);
  389.    if (xf == NULL) return;
  390.  
  391.    if (DECL_NAME(decl) == NULL) return;
  392.  
  393.    if (TREE_CODE(decl) == TYPE_DECL) cls = "TYPEDEF";
  394.    else if (TREE_CODE(decl) == FIELD_DECL) cls = "FIELD";
  395.    else if (TREE_CODE(decl) == VAR_DECL) {
  396.       if (fct == NULL && TREE_STATIC(decl) &&
  397.          TREE_READONLY(decl) && DECL_INITIAL(decl) != 0 &&
  398.          !TREE_PUBLIC(decl) && !TREE_EXTERNAL(decl) &&
  399.          DECL_MODE(decl) != BLKmode) cls = "CONST";
  400.       else if (TREE_EXTERNAL(decl)) cls = "EXTERN";
  401.       else if (TREE_PUBLIC(decl)) cls = "EXTDEF";
  402.       else if (TREE_STATIC(decl)) cls = "STATIC";
  403.       else if (TREE_REGDECL(decl)) cls = "REGISTER";
  404.       else cls = "AUTO";
  405.     }
  406.    else if (TREE_CODE(decl) == PARM_DECL) cls = "PARAM";
  407.    else if (TREE_CODE(decl) == FIELD_DECL) cls = "FIELD";
  408.    else if (TREE_CODE(decl) == CONST_DECL) cls = "CONST";
  409.    else if (TREE_CODE(decl) == FUNCTION_DECL) {
  410.       if (TREE_EXTERNAL(decl)) cls = "EXTERN";
  411.       else if (TREE_PUBLIC(decl)) cls = "EFUNCTION";
  412.       else cls = "SFUNCTION";
  413.     }
  414.    else if (TREE_CODE(decl) == LABEL_DECL) cls = "LABEL";
  415.    else if (TREE_CODE(decl) == UNION_TYPE) {
  416.       cls = "UNIONID";
  417.       decl = TYPE_NAME(decl);
  418.     }
  419.    else if (TREE_CODE(decl) == RECORD_TYPE) {
  420.       if (CLASSTYPE_DECLARED_CLASS(decl)) cls = "CLASSID";
  421.       else cls = "STRUCTID";
  422.       decl = TYPE_NAME(decl);
  423.     }
  424.    else if (TREE_CODE(decl) == ENUMERAL_TYPE) {
  425.       cls = "ENUMID";
  426.       decl = TYPE_NAME(decl);
  427.     }
  428.    else cls = "UNKNOWN";
  429.  
  430.    name = IDENTIFIER_POINTER(DECL_NAME(decl));
  431.  
  432.    type_as_string(buf,TREE_TYPE(decl));
  433.    simplify_type(buf);
  434.  
  435.    fprintf(xref_file,"DCL %s %d %s %d %s %s %s\n",
  436.           filename(xf),lineno,name,
  437.           (cur_scope != NULL ? cur_scope->lid : 0),
  438.           cls,fctname(fct),buf);
  439. };
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446. /************************************************************************/
  447. /*                                    */
  448. /*    FIELD_xref_call -- handle call                    */
  449. /*                                    */
  450. /************************************************************************/
  451.  
  452.  
  453. void
  454. FIELD_xref_call(fct,name)
  455.    tree fct;
  456.    String name;
  457. {
  458.    XREF_FILE xf;
  459.    char buf[1024];
  460.  
  461.    if (!doing_xref) return;
  462.    xf = find_file(input_filename);
  463.    if (xf == NULL) return;
  464.    name = fixname(name,buf);
  465.  
  466.    fprintf(xref_file,"CAL %s %d %s %s\n",
  467.           filename(xf),lineno,name,fctname(fct));
  468. };
  469.  
  470.  
  471.  
  472.  
  473.  
  474.  
  475. /************************************************************************/
  476. /*                                    */
  477. /*    FIELD_xref_function -- handle functions             */
  478. /*                                    */
  479. /************************************************************************/
  480.  
  481.  
  482. void
  483. FIELD_xref_function(fct,args)
  484.    tree fct;
  485.    tree args;
  486. {
  487.    XREF_FILE xf;
  488.    int ct;
  489.    char buf[1024];
  490.  
  491.    if (!doing_xref) return;
  492.    xf = find_file(input_filename);
  493.    if (xf == NULL) return;
  494.  
  495.    ct = 0;
  496.    buf[0] = 0;
  497.    if (args == NULL) args = DECL_ARGUMENTS(fct);
  498.  
  499.    FIELD_xref_decl(NULL,fct);
  500.  
  501.    for ( ; args != NULL; args = TREE_CHAIN(args)) {
  502.       FIELD_xref_decl(fct,args);
  503.       if (ct != 0) strcat(buf,",");
  504.       strcat(buf,declname(args));
  505.       ++ct;
  506.     };
  507.  
  508.    fprintf(xref_file,"PRC %s %d %s %d %d %s\n",
  509.           filename(xf),lineno,declname(fct),
  510.           (cur_scope != NULL ? cur_scope->lid : 0),
  511.           ct,buf);
  512. };
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519. /************************************************************************/
  520. /*                                    */
  521. /*    FIELD_xref_assign -- handle assignment                */
  522. /*                                    */
  523. /************************************************************************/
  524.  
  525.  
  526. void
  527. FIELD_xref_assign(name)
  528.    tree name;
  529. {
  530.    XREF_FILE xf;
  531.  
  532.    if (!doing_xref) return;
  533.    xf = find_file(input_filename);
  534.    if (xf == NULL) return;
  535.  
  536.    gen_assign(xf,name);
  537. };
  538.  
  539.  
  540.  
  541. static void
  542. gen_assign(xf,name)
  543.    XREF_FILE xf;
  544.    tree name;
  545. {
  546.    String s;
  547.  
  548.    s = NULL;
  549.  
  550.    switch (TREE_CODE(name)) {
  551.       case IDENTIFIER_NODE :
  552.      s = IDENTIFIER_POINTER(name);
  553.      break;
  554.       case VAR_DECL :
  555.      s = declname(name);
  556.      break;
  557.       case COMPONENT_REF :
  558.      gen_assign(xf,TREE_OPERAND(name,0));
  559.      gen_assign(xf,TREE_OPERAND(name,1));
  560.      break;
  561.       case INDIRECT_REF :
  562.       case OFFSET_REF :
  563.       case ARRAY_REF :
  564.       case BUFFER_REF :
  565.      gen_assign(xf,TREE_OPERAND(name,0));
  566.      break;
  567.       case COMPOUND_EXPR :
  568.      gen_assign(xf,TREE_OPERAND(name,1));
  569.      break;
  570.       default :
  571.      break;
  572.     };
  573.  
  574.    if (s != NULL) {
  575.       fprintf(xref_file,"ASG %s %d %s\n",filename(xf),lineno,s);
  576.     };
  577. };
  578.  
  579.  
  580.  
  581.  
  582.  
  583. /************************************************************************/
  584. /*                                    */
  585. /*    FIELD_xref_hier -- handle hierarchy                */
  586. /*                                    */
  587. /************************************************************************/
  588.  
  589.  
  590. void
  591. FIELD_xref_hier(cls,base,pub,virt,frnd)
  592.    String cls;
  593.    String base;
  594.    int pub;
  595.    int virt;
  596.    int frnd;
  597. {
  598.    XREF_FILE xf;
  599.  
  600.    if (!doing_xref) return;
  601.    xf = find_file(input_filename);
  602.    if (xf == NULL) return;
  603.  
  604.    fprintf(xref_file,"HIE %s %d %s %s %d %d %d\n",
  605.           filename(xf),lineno,cls,base,pub,virt,frnd);
  606. };
  607.  
  608.  
  609.  
  610.  
  611.  
  612. /************************************************************************/
  613. /*                                    */
  614. /*    FIELD_xref_member -- handle member                */
  615. /*                                    */
  616. /************************************************************************/
  617.  
  618.  
  619. void
  620. FIELD_xref_member(cls,fld)
  621.    tree cls;
  622.    tree fld;
  623. {
  624.    XREF_FILE xf;
  625.    String prot;
  626.    Integer confg,pure;
  627.    String d,p;
  628.    Integer i;
  629.    char buf[1024],bufa[1024];
  630.  
  631.    if (!doing_xref) return;
  632.    xf = find_file(fld->decl.filename);
  633.    if (xf == NULL) return;
  634.  
  635.    if (TREE_PRIVATE(fld)) prot = "PRIVATE";
  636.    else if (TREE_PROTECTED(fld)) prot = "PROTECTED";
  637.    else prot = "PUBLIC";
  638.  
  639.    confg = 0;
  640.    if (TREE_CODE(fld) == FUNCTION_DECL && DECL_CONST_MEMFUNC_P(fld)) confg = 1;
  641.    else if (TREE_CODE(fld) == CONST_DECL) confg = 1;
  642.  
  643.    pure = 0;
  644.    if (TREE_CODE(fld) == FUNCTION_DECL && DECL_ABSTRACT_VIRTUAL_P(fld)) pure = 1;
  645.  
  646.    d = IDENTIFIER_POINTER(cls);
  647.    sprintf(buf,"%d%s",strlen(d),d);
  648.    i = strlen(buf);
  649.    strcpy(bufa,declname(fld));
  650.    for (p = &bufa[1]; *p != 0; ++p) {
  651.       if (p[0] == '_' && p[1] == '_' && p[2] >= '0' && p[2] <= '9') {
  652.      if (strncmp(&p[2],buf,i) == 0) *p = 0;
  653.      break;
  654.        }
  655.       else if (p[0] == '_' && p[1] == '_' && p[2] == 'C' && p[3] >= '0' && p[3] <= '9') {
  656.      if (strncmp(&p[3],buf,i) == 0) *p = 0;
  657.      break;
  658.        };
  659.     };
  660.  
  661.    fprintf(xref_file,"MEM %s %d %s %s %s %d %d %d %d %d %d %d\n",
  662.           filename(xf),fld->decl.linenum,d,
  663.           bufa,
  664.           prot,
  665.           (TREE_CODE(fld) == FUNCTION_DECL ? 0 : 1),
  666.           (TREE_INLINE(fld) ? 1 : 0),
  667.           (DECL_FRIEND_P(fld) ? 1 : 0),
  668.           (DECL_VIRTUAL_P(fld) ? 1 : 0),
  669.           (TREE_STATIC(fld) ? 1 : 0),
  670.           pure,confg);
  671. };
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678. /************************************************************************/
  679. /*                                    */
  680. /*    find_file -- find file entry given name             */
  681. /*                                    */
  682. /************************************************************************/
  683.  
  684.  
  685.  
  686. static XREF_FILE
  687. find_file(name)
  688.    String name;
  689. {
  690.    XREF_FILE xf;
  691.  
  692.    for (xf = all_files; xf != NULL; xf = xf->next) {
  693.       if (STREQL(name,xf->name)) break;
  694.     };
  695.  
  696.    return xf;
  697. };
  698.  
  699.  
  700.  
  701.  
  702.  
  703. /************************************************************************/
  704. /*                                    */
  705. /*    filename -- return name for output                */
  706. /*                                    */
  707. /************************************************************************/
  708.  
  709.  
  710. static String
  711. filename(xf)
  712.    XREF_FILE xf;
  713. {
  714.    if (xf == NULL) {
  715.       last_file = NULL;
  716.       return "*";
  717.     };
  718.  
  719.    if (last_file == xf) return "*";
  720.  
  721.    last_file = xf;
  722.  
  723.    return xf->name;
  724. };
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731. /************************************************************************/
  732. /*                                    */
  733. /*    fctname -- return name for function                */
  734. /*                                    */
  735. /************************************************************************/
  736.  
  737.  
  738. static String
  739. fctname(fct)
  740.    tree fct;
  741. {
  742.    extern char * declname();
  743.    static char fctbuf[1024];
  744.    String s;
  745.  
  746.    if (fct == NULL && last_fct == NULL) return "*";
  747.  
  748.    if (fct == NULL) {
  749.       last_fct = NULL;
  750.       return "*TOP*";
  751.     };
  752.  
  753.    if (fct == last_fct) return "*";
  754.  
  755.    last_fct = fct;
  756.  
  757.    s = declname(fct);
  758.    s = fixname(s,fctbuf);
  759.  
  760.    return s;
  761. };
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768. /************************************************************************/
  769. /*                                    */
  770. /*    declname -- print name for declaration                */
  771. /*                                    */
  772. /************************************************************************/
  773.  
  774.  
  775. static String
  776. declname(dcl)
  777.    tree dcl;
  778. {
  779.    if (DECL_NAME(dcl) == NULL) return "?";
  780.  
  781.    return IDENTIFIER_POINTER (DECL_NAME (dcl));
  782. }
  783.  
  784.  
  785.  
  786.  
  787.  
  788. /************************************************************************/
  789. /*                                    */
  790. /*    simplify_type -- simplify a type string             */
  791. /*                                    */
  792. /************************************************************************/
  793.  
  794.  
  795. static void
  796. simplify_type(typ)
  797.    String typ;
  798. {
  799.    String s;
  800.    Integer lvl,i;
  801.  
  802.    i = strlen(typ);
  803.    while (i > 0 && isspace(typ[i-1])) typ[--i] = 0;
  804.  
  805.    if (i > 7 && STREQL(&typ[i-5],"const")) {
  806.       typ[i-5] = 0;
  807.       i -= 5;
  808.     };
  809.  
  810.    if (typ[i-1] != ')') return;
  811.  
  812.    s = &typ[i-2];
  813.    lvl = 1;
  814.    while (*s != 0) {
  815.       if (*s == ')') ++lvl;
  816.       else if (*s == '(') {
  817.      --lvl;
  818.      if (lvl == 0) {
  819.         s[1] = ')';
  820.         s[2] = 0;
  821.         break;
  822.       };
  823.        };
  824.       --s;
  825.     };
  826.  
  827.    if (*s != 0 && s[-1] == ')') {
  828.       --s;
  829.       --s;
  830.       if (*s == '(') s[2] = 0;
  831.       else if (*s == ':') {
  832.      while (*s != '(') --s;
  833.      s[1] = ')';
  834.      s[2] = 0;
  835.        };
  836.     };
  837. };
  838.  
  839.  
  840.  
  841.  
  842.  
  843. /************************************************************************/
  844. /*                                    */
  845. /*    fixname -- fixup a function name (take care of embedded spaces    */
  846. /*                                    */
  847. /************************************************************************/
  848.  
  849.  
  850. static String
  851. fixname(nam,buf)
  852.    String nam;
  853.    String buf;
  854. {
  855.    String s,t;
  856.    int fg;
  857.  
  858.    s = nam;
  859.    t = buf;
  860.    fg = 0;
  861.  
  862.    while (*s != 0) {
  863.       if (*s == ' ') {
  864.      *t++ = '\36';
  865.      ++fg;
  866.        }
  867.       else *t++ = *s;
  868.       ++s;
  869.     };
  870.  
  871.    if (fg == 0) return nam;
  872.  
  873.    return buf;
  874. };
  875.  
  876.  
  877.  
  878.  
  879.  
  880. /************************************************************************/
  881. /*                                    */
  882. /*    open_xref_file -- open file for xrefing             */
  883. /*                                    */
  884. /************************************************************************/
  885.  
  886.  
  887. static void
  888. open_xref_file(file)
  889.    String file;
  890. {
  891.    String s,t;
  892.  
  893.    s = rindex(file,'/');
  894.    if (s == NULL) sprintf(xref_name,".%s.gxref",file);
  895.    else {
  896.       ++s;
  897.       strcpy(xref_name,file);
  898.       t = rindex(xref_name,'/');
  899.       ++t;
  900.       *t++ = '.';
  901.       strcpy(t,s);
  902.       strcat(t,".gxref");
  903.     };
  904.  
  905.    xref_file = fopen(xref_name,"w");
  906.  
  907.    if (xref_file == NULL) {
  908.       error("Can't create cross-reference file `%s'",xref_name);
  909.       doing_xref = 0;
  910.     };
  911. };
  912.  
  913.  
  914.  
  915. #endif
  916.  
  917.  
  918. /* end of cplus-field.c */
  919.